package com.sunjy.common.utils;

import java.math.BigDecimal;

public class CalFeeUtil {


	//==============================账单计算逻辑对外接口   bgn ============================== 
	
	public static BigDecimal calFee(BigDecimal base,BigDecimal percent,BigDecimal staticMoney,short carryRule){
		BigDecimal retFee = null;
		BigDecimal orgBase = base.multiply(percent.divide(new BigDecimal(100)));//个人
		retFee = carryProcess(orgBase,carryRule).add(staticMoney);
		return retFee;
	}

	public static BigDecimal calBase(BigDecimal base,BigDecimal percent,BigDecimal staticMoney,short carryRule){
		return  base.multiply(percent.divide(new BigDecimal(100))).add(staticMoney);//个人;
	}
	//==============================账单计算逻辑对外接口   end ==============================
	


	public static BigDecimal carryProcess(BigDecimal money, short personRule){

		BigDecimal ret = new BigDecimal(0);
		if(personRule == 1){
			ret = CarryRuleUtil.roundToFen(money);
		}
		if(personRule == 2){
			ret = CarryRuleUtil.roundToJiao(money);
		}
		if(personRule == 3){
			ret = CarryRuleUtil.roundToYuan(money);
		}
		if(personRule == 4){
			ret = CarryRuleUtil.upToYuan(money);
		}
		if(personRule == 5){
			ret = CarryRuleUtil.downToYuan(money);
		}
		if(personRule == 6){
			ret = CarryRuleUtil.upToFen(money);
		}
		if(personRule == 7){
			ret = CarryRuleUtil.upToJiao(money);
		}
		if(personRule == 8){
			ret = CarryRuleUtil.jiaoUpToYuan(money);
		}
		if(personRule == 9){
			ret = CarryRuleUtil.roundFenAndUpToYuan(money);
		}
		if(personRule == 10){
			ret = CarryRuleUtil.jiaoToYuan(money);
		}
		if(personRule == 11){
			ret = CarryRuleUtil.roundTo10(money);
		}

		return ret;
	}
	
	public static BigDecimal getConformUpperAndLowerBase(BigDecimal base,BigDecimal baseUp,BigDecimal baseDown){
		
		//险种基数非无上限时，如果 客户申报基数/预采基数 > 险种基数上限，缴费基数 = 险种基数上限 
		if(baseUp.compareTo(new BigDecimal(0)) != 0){
			if(base.compareTo(baseUp) == 1){
				base = baseUp;
			}
		}
		
		//险种基数非无下限时，如果 客户申报基数/预采基数 < 险种基数下限，缴费基数 = 险种基数下限 
		if(baseDown.compareTo(new BigDecimal(0)) != 0){
			if(base.compareTo(baseDown) == -1){
				base = baseDown;
			}
		}
		return base;
	}
	
}
